package com.xyebank.ledger.service.sjsh.dataProvider.credit;

import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.service.sjsh.dataProvider.credit.SJSHCashCredit;
import com.xyebank.ledger.service.sjsh.dataProvider.credit.SJSHCashCreditMapper;
import com.xyebank.ledger.vo.deal.SJSHCashCreditVo;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class SJSHCashCreditProvider implements DataProvider<SJSHCashCreditVo> {

	@Autowired
	private SJSHCashCreditMapper sjshCashCreditMapper;

	@Override
	public List<SJSHCashCreditVo> get(Integer fromIdx, Integer tarNum) {
		List<SJSHCashCredit> result = sjshCashCreditMapper.selectByPaging(fromIdx, tarNum);
		List<SJSHCashCreditVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public List<SJSHCashCreditVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {
		List<SJSHCashCredit> result = sjshCashCreditMapper.selectByPeriod(dateStart, dateEnd, fromIdx, tarNum);
		List<SJSHCashCreditVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public Integer count(Date timeStart, Date timeEnd) {
		Integer num = sjshCashCreditMapper.selectPeriodCount(timeStart, timeEnd);
		return num;
	}

	private List<SJSHCashCreditVo> convert2Vo(List<SJSHCashCredit> result) {
		List<SJSHCashCreditVo> list = new ArrayList<SJSHCashCreditVo>();
		for (int i = 0; i < result.size(); i++) {
			SJSHCashCreditVo vo = new SJSHCashCreditVo();
			BeanUtils.copyProperties(result.get(i), vo);
			list.add(vo);
		}
		return list;
	}

}
